<?php

/**
 * IndexController - The default controller class
 *
 * @author
 * @version
 */

require_once 'Zend/Controller/Action.php';

class Administrator_locationController extends Zend_Controller_Action
{
    public function init()
    {

        $member=new CMember();

        if(!$member->isUser($this->_request->getModuleName(),$this->_request->getControllerName()))
        {

            $this->_redirect(MY_URL.'/administrator-auth-login');

        }
    	$memberArray = $member->getUserDetails(array('uid' => $_COOKIE[COOKIE_PRE.'uid']));
    	if($_COOKIE[COOKIE_PRE.'uid']=='1'){
				
		} else {
        	$strarray = explode(",", $memberArray[0]['menuflag']);
        	
        	if (!in_array('6', $strarray)) {
        		exit('no priviage');
        	}
		}

    }

    public function preDispatch()
    {

        $this->getHelper ('layout')->setLayout('framelayout');

        $this->view->addHelperPath(MY_ROOT.'/vhelpers');

        Zend_Controller_Action_HelperBroker::addPath(MY_ROOT.'/chelpers');

    //$this->getHelper('User')->getinfo($this->view,$this->_request->getModuleName(),$this->_request->getControllerName());

    }

    public function indexAction()
    {

        $type=$this->_request->getParam('type');

        $typefl=new CFenlei($type);

        $fenleiArray=$typefl->getAllFenleiByOrder();

        $typefl->getAlllocationFenleiManagement($fenleiArray,0);

        $fenleiString=str_replace(array('<div class="smallChildDiv"></div>','<div></div>'),array('',''),$typefl->fenleiString);

        $this->view->assign('fenleiString',$fenleiString);

        $this->view->assign('type',$type);

    }

    public function editAction()
    {

        $itemid=$this->_request->getParam('itemid');

        $CFenlei=new CFenlei("location");

        $oneFenleiArray=$CFenlei->getoneFenlei($itemid);

        $lagnappeselectArray=$CFenlei->getFenleiByPid('213');

        // die($oneFenleiArray[0]["flname"]."a");

        $Cyunfei=new Cyunfei();

        $selectyunfeiArray=$Cyunfei->getAllyunfei();

        $this->view->assign('selectyunfeiArray',$selectyunfeiArray);
        
        $this->view->assign('oneFenleiArray',$oneFenleiArray);

        $this->view->assign('lagnappeselectArray',$lagnappeselectArray);

        $yunfeiArray=$Cyunfei->getyunfeiIN($oneFenleiArray[0]['yunfei']);

        $this->view->assign('yunfeiArray',$yunfeiArray);

    }

    public function doeditAction()
    {

        $this->_helper->viewRenderer->setNoRender();

        if(!$this->getRequest()->isPost())
        {

            $this->view->showMsg("发生未知错误!");

            return false;
        }

        $paramArray=$this->_request->getParams();

        $itemid=$paramArray['itemid'];

        if($_POST[yunfei])
        {
        $yunfei = join(",",$_POST[yunfei]);
        }

        $filters = array(
            '*'   => 'StringTrim'
        );

        $validators = array(
        );

        $input = new Zend_Filter_Input($filters, $validators, $paramArray);

      
        /*修改公告表 start*/

        $fenlei=new CFenlei("location");

        $data=array(
            'flname'=>trim($_POST[flname]),
            'en_flname'=>trim($_POST[en_flname]),
            'yunfei'=>trim($yunfei),
        );

        ///die($_POST[flname]);
        $fenlei->editFenlei($itemid,$data);

		/*修改公告表 end*/

        $this->view->showMsg("修改成功!",'administrator-location-index?type=location');

        return true;

    }
    public function alterAction()
    {

        $this->_helper->viewRenderer->setNoRender();

        $thisArray=$this->_request->getParams();

        if(trim($thisArray['flname'])!='')
        {

            $type=$thisArray['type'];

            $fenlei=new CFenlei($type);

            $fenlei->editFenlei($thisArray['flid'],array('flname'=>trim($thisArray['flname']),'en_flname'=>trim($thisArray['en_flname'])));

            $this->_forward('index');

        }

    }

    public function newAction()
    {

        $this->_helper->viewRenderer->setNoRender();

        $thisArray=$this->_request->getParams();

        if(trim($thisArray['flname'])!='')
        {

            $type=$thisArray['type'];

            $fenlei=new CFenlei($type);

            $fenlei->createFenlei(array('flname'=>trim($thisArray['flname']),'en_flname'=>trim($thisArray['en_flname']),'pid'=>$thisArray['flid']));

            $this->_forward('index');
        }

    }

    public function dodelAction()
    {

        $this->_helper->viewRenderer->setNoRender();

        $thisArray=$this->_request->getParams();

        if(is_numeric($thisArray['flid']))
        {

            $type=$thisArray['type'];

            $fenlei=new CFenlei($type);

            $fenlei->delFenlei($thisArray['flid']);

            $this->_forward('index');
        }

    }


    public function postAction()
    {

    //$this->_helper->viewRenderer->setNoRender();

    //$this->getHelper ('layout')->disableLayout ();

    }



}
